<?php

// include function files for this application
require_once('/home/domains/uny-con.com/public_html/uny-con_fns.php'); 
if (!session_id()) { session_start(); }

if (!check_valid_user()) {
	// they are not logged in 
	do_html_header('You must be logged in', staysmall, $uny);
	echo 'You are not logged in.<br />';
	do_html_url('login.php', 'Login');
	print_brs(24);
	do_html_footer(news);
	exit;
	}

//get some variables:
if (isset($_GET['attendee_id']) && !empty($_GET['attendee_id']) && $_SESSION['admin'] == 't') {
	$requested_id = $_GET['attendee_id'];
	$_SESSION['current_attendee_id'] = $requested_id;
	}
if (isset($_SESSION['current_attendee_id']))
	$requested_id = $_SESSION['current_attendee_id'];

if ($_GET['check_in'] == 'Y') {
	check_in_to_con($requested_id, $_SESSION['attendee_id']);
	header("Location: ".$conf['base_path']."registration/attendee_home.php?attendee_id=$requested_id");
	}


do_html_header('UNY-Con user registration home', gobig, $uny);

/* I am not sure we can make this section work with badge types from the DB
// Here we get all the info on the number of events a user is running to update their status transparently to them if need be.
$registration_status = get_con_attendance_status($_SESSION['current_attendee_id']);

//get the events the user is running
if ($cogmevents = get_cogm_events($requested_id, pending))
	$cogmnumpending = pg_numrows($cogmevents);
$running_timeslots = get_number_of_events_run($_SESSION['current_attendee_id']);

//This will prevent GMs who have dropped back below 4 events from getting in free.
$con_reg_info_array = get_con_reg_info($_SESSION['current_attendee_id']);
	if ($registration_status == "approved") {
		if (($running_timeslots < '16 hours') && ($con_reg_info_array['reg_type'] == 'gm') && ($con_reg_info_array['cost'] == '0.00')) {
			update_con_status('all week-end', pending, $_SESSION['current_attendee_id'], 'general admit pre-reg', 25.00, $_SESSION['attendee_id']);
			$registration_status = 'pending';
			}
		if (($con_reg_info_array['reg_type'] == 'general admit pre-reg' || $con_reg_info_array['reg_type'] == 'general admit on-site') && $running_timeslots >= '16 hours') {
			update_con_status("all week-end", approved, $_SESSION['current_attendee_id'], 'gm', 0.00, $_SESSION['attendee_id']);
			$registration_status = 'approved';
			}
		}
	if ($registration_status == '' || empty($registration_status)) {
		if ($running_timeslots >= '16 hours') {
			insert_con_registration($_SESSION['current_attendee_id'], 'all week-end', 'gm', '0.00', 'approved', $_SESSION['attendee_id']);
			$registration_status = "approved";
			} else {
			$registration_status = "unregistered";
			}
		}
	if ($registration_status == 'pending') {
		if ($running_timeslots >= '16 hours' ) {
			update_con_status("all week-end", approved, $_SESSION['current_attendee_id'], 'gm', 0.00, $_SESSION['attendee_id']);
			$registration_status = 'approved';
			} else {
			$registration_status = "<span class=\"redtext\">pending</span>";
			}
		}
// end status updating section.
*/

display_user_info(get_user_info($_SESSION['current_attendee_id']));
if (check_valid_user()) {
//people can not be expected to scroll to the bottom of the page. to see this information
if ($pendingevents = get_attend_events($_SESSION['current_attendee_id'], pending)) {
	echo "<p><span class=\"redtext\">You have signed up to play events that are still pending events. Please scroll down and see if you need to pay for them.</span></p>";
	}
$cogmswaiting = get_event_cogms($_SESSION['current_attendee_id'], unapproved);
if (pg_numrows($cogmswaiting) > '0') {
	echo "<p><span class=\"redtext\">Note</span> there are people signed to Co-GM some of your events that you have not approved or denied. Please do so <a href=\"manage_gms.php\">now</a></p>";
	}

echo "<h2>Convention Registration Status</h2>";
if ($_SESSION['admin'] == 't') {
	$admin_change_status = " <a href=\"http://loki.local/~plummer/uny-con/registration/modify_user_con_reg.php?edit_id=$requested_id\">[change]</a>";
	}
if ($registration_status == '<span class="redtext">pending</span>' && (($running_timeslots + $cogmnumpending) < '16 hours') && $_SESSION['admin'] != 't') {
	$checkoutnote = '<p>Select the Checkout button below to pay for your Convention registration or select more events before checking out.<br><a href="checkout.php"><img src="images/check-out.gif" alt="Go to Check Out" width="140" height="40" border="0"></a></p>';
	}
if ($registration_status == 'approved') {
	$registration_status = "<span class=\"greentext\">registered</span>";
	}
if ($registration_status == 'denied') {
	$registration_status = "<span>class=\"redtext\">denied</span>";
	}
$attendance_type = get_con_attendance_type($requested_id);
if ($attendance_type == "special") {
	$attendance_type = "<span class=\"redtext\">special</span>";
	}
	
if ($registration_status == '<span class="yellowtext">Unregistered</span>') {
	echo "Convention status is $registration_status. $admin_change_status";
	} else {
	echo "<p>Convention status is $registration_status for a $attendance_type pass good  ".get_con_attendance_day($requested_id).". $admin_change_status";
	}
	echo $checkoutnote;
	
echo '<h2>You have submitted the following events</h2>';
if ($gmevents = get_gm_events($_SESSION['current_attendee_id'])) {
	if (check_for_rpga($gmevents)) {
		echo 'You appear to be coordinating RPGA events. You can view a list of current GM needs <a href="manage_rpga_events.php">here</a>.';
		}
	print_event_table($gmevents, GM);
	} else {
	echo '<p>You are not registered to run any events.</p>';
	}
	
echo "<h2>Co-GM for these events</h2>";
if ($cogmevents = get_cogm_events($_SESSION['current_attendee_id'], approved)) {
	print_event_table($cogmevents);
	} else {
		echo "<p>You have not been approved as a Co-GM for any events <a href=\"event_list.php\">sign-up</a>now.</p>";
		}
if ($cogmevents = get_cogm_events($_SESSION['current_attendee_id'], pending)) {
	echo "<p>The following events are awaiting the owners approval for you to Co-GM them. you can <a href=\"event_list.php\">sign-up</a> for more.</p>";
	print_event_table($cogmevents);
	}

echo "<h2>Participating in these events</h2>";
/* This section prints the quick reg menus and is commented out because its broken
if ($_SESSION['admin'] == 't') {
	if ($registration_status = get_con_attendance_status($requested_id)) {
		$event_day=get_con_attendance_day($requested_id);
		$min=get_min_ts_reg($event_day);
		$max=get_max_ts_reg($event_day);
		$i = $min;
		$c = '0';
		//if (!check_attendee_timeslot_reg($requested_id, 0) && $attendance_type != 'gm only') {
		//	$event_id_menu = print_event_id_menu(0, $requested_id, $c++);
		//	$printed = 'Y';
		//	}
		for ( ;$i <= $max ; $i++) {
			if (!check_attendee_timeslot_reg($requested_id, $start_time) && $attendance_type != 'gm only') {
				$event_id_menu .= print_event_id_menu($i, $requested_id, $c++);
				$printed = 'Y';
				}
			}
		if ($printed = 'Y' && $attendance_type != 'gm only') {
			echo "<form method=post action=\"process_menu_reg.php\">\n";
			echo $event_id_menu."<br />";
			echo "<input type=submit value=\"Process\">\n</form>";
			}
		$i = $min;
		print_event_search_form();
		}
	}
*/
if ($pendingevents = get_attend_events($_SESSION['current_attendee_id'], pending)) {
	echo "<p>Some of the below events have registration fees and are pending approval. If you have not already done so select checkout below and pay for them.</p>";
	}
if ($attendevents = get_attend_events($_SESSION['current_attendee_id'], all)) {
	print_event_table($attendevents, attend);
	if ($pendingevents = get_attend_events($_SESSION['current_attendee_id'], pending)) {
		echo '<br /><a href="checkout.php"><img src="images/check-out.gif" alt="Go to Check Out" width="140" height="40" border="0"></a>';
		}
	} else {
		echo '<p>You are not participating in any events.</p>';
		}
	}
do_html_footer(no_news);
?>